Skip to content

fix(structured_output): do not modify conversation_history when prompt is passed #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2025

Conversation

dbschmigelski
Copy link
Member

Description

A customer brought up the following concern regarding using structured_output on an agent.

If I use the alternate method, first go through one agent loop using result = agent(user_message)  and then agent.structured_output(<pydantic model>, result) , then there are 2 problems -
Won’t passing the result again as a “prompt” pollute the context window?
{ignore problem 2}

Adding the prompt to the conversation history seems like a bug. We are indicating that we want a particular message structured, but we never add the result to the conversation history.

So, we can either not append or we can add the result of the structuring after it is complete. I am biased towards the former. This is because structured output is not an action taken by the agent. Rather, it is more similar to a utility function for the user to format the result of an agent invocation. The structuring of the output is not itself an invocation in the same sense - especially since it is making a model request with only a single, non-user defined, tool.

Documentation PR

No documentation updates needed after inspecting https://strandsagents.com/latest/documentation/docs/user-guide/concepts/agents/structured-output/

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@dbschmigelski dbschmigelski merged commit adac26f into strands-agents:main Aug 8, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants